package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lenovo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2024-06-18 14:38:03
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Autowired
    private RoomInfoService roomInfoService;
    @Autowired
    private PaymentTypeService paymentTypeService;
    @Autowired
    private LeaseTermService leaseTermService;

    @Override
    public IPage<AgreementVo> pageInfo(IPage<AgreementVo> iPage, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageInfo(iPage, queryVo);
    }

    @Override
    public AgreementVo getLeaseById(Long id) {
        AgreementVo agreementVo = new AgreementVo();
        //查询租约基本信息
        LeaseAgreement leaseAgreement = super.getById(id);
        //查询所属公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(leaseAgreement.getApartmentId());
        //查询所属房间信息
        RoomInfo roomInfo = roomInfoService.getById(leaseAgreement.getRoomId());
        //查询支付方式信息
        PaymentType paymentType = paymentTypeService.getById(leaseAgreement.getPaymentTypeId());
        //查询租期信息
        LeaseTerm leaseTerm = leaseTermService.getById(leaseAgreement);

        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);
        BeanUtils.copyProperties(leaseAgreement,agreementVo);

        return agreementVo;
    }
}




